package com.catmiw.stock.service;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.catmiw.stock.dao.EarningsMapper;
import com.catmiw.stock.domain.Earnings;

public class EarningsServiceImpl implements EarningsService {

	public int insertAll(List<Earnings> ins) {
		SqlSession session=SessionFactory.getInstance().getSession();
		EarningsMapper cm=session.getMapper(EarningsMapper.class);
		int count=0;
		
		for (Earnings icm:ins){
			//System.out.println(icm.getCode()+"\t"+icm.getDate()+
			//		"\t"+icm.getTotal()+"\t"+icm.getNetProfit());
			cm.insert(icm);
			count++;
		}
		session.commit();
		session.close();
		
		return count;
	}

	public void deleteAll() {
		SqlSession session=SessionFactory.getInstance().getSession();
		EarningsMapper cm=session.getMapper(EarningsMapper.class);
		cm.deleteAll();
		session.commit();
		session.close();
	}

	public List<Earnings> selectCode(String code) {
		SqlSession session=SessionFactory.getInstance().getSession();
		EarningsMapper cm=session.getMapper(EarningsMapper.class);
		List<Earnings> le=(List<Earnings>)cm.selectCode(code);
		session.commit();
		session.close();
		return le;
	}

}
